﻿using System.Web;
using System.Web.Script.Serialization;
using SuddenDeath.Domain.Services.FileManager.elFinder.Responses;

namespace SuddenDeath.Domain.Services.FileManager.elFinder
{
    public class Connector : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
            Configuration.Configuration.Init(context);

            var dispatcher = new CommandDispatcher(context.Request);

            var response = dispatcher.DispatchCommand();

            switch (response.ContentType)
            {
                case ContentType.Json:
                    var js = new JavaScriptSerializer();
                    string x = js.Serialize(response);
                    context.Response.Write(x);
                    break;
                case ContentType.Ping:
                    context.Response.End();
                    break;
            }

            //context.Response.Write("test");
        }

        #endregion
    }
}
